import com.google.appengine.api.datastore.*
import static com.google.appengine.api.datastore.FetchOptions.Builder.*

//this.class.classLoader.rootLoader.addURL(new URL("file:////usr/local/groovy/lib/graphicsbuilder-0.6.1.jar"))
//def GraphicsBuilder = Class.forName("groovy.swing.j2d.GraphicsBuilder").newInstance()

def query = new Query("article")

query.addSort("pubTime", Query.SortDirection.DESCENDING)

PreparedQuery pq = datastore.prepare(query)

def pageindex = 0

if(params['page']){
	pageindex = ((params['page'] as Integer)- 1)*5
}

def articles = pq.asList(withLimit(5).offset(pageindex))

request.setAttribute 'page', params['page']== null ? 1 : params['page'] 

request.setAttribute 'blogs', articles

forward "index.gtpl"